% This function takes a rental rate and spillovers and return the difference between the housing supply
% and housing demand. We search over the rental rate to find the one that sets supply equal to demand
function share_diff = find_rents_ss(rs, Ss, share, Prob)
    global bet0 bet1 tau a b w e pi_theta N_a N_theta N_w N_e w_max w_min alpha xi xi1 ub lb pi_e H w theta Int_pi_w sigmae elasts...
        phi sigma  rts e_curr r_base pe idx_pe
   
    % Calculate wage pdf and cdf
    pi_w = sum(Prob, 2);
    cdf_w = cumsum(pi_w,1);
    idx_pe = find(cdf_w>0.25,1);
    
    % Calculate Choice Probabilities
    P_S = choiceProb(Ss, rs);
    
    % Calculate housing demand
    H_dem = sum(sum(bsxfun(@times, P_S, Prob), 1), 2);
    H_dem = squeeze(H_dem);
    H_dem = bsxfun(@times, H_dem, pi_theta);
    H_dem = sum(H_dem, 2);
    
    H_dem = H_dem(:)   ;
    share_diff = H_dem - (share);


end